package com.jinyu.jyly.ui.mine.sell;

import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
import com.jinyu.jyly.R;
import com.jinyu.jyly.base.BaseActivity;
import com.jinyu.jyly.bean.AllInfoBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 我的卖单
 */
public class MineSellActivity extends BaseActivity<MineSellPresenter> implements MineSellContract.View {

    @BindView(R.id.fake_status_bar)
    View fakeStatusBar;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.rl_title_view)
    RelativeLayout rlTitleView;
    @BindView(R.id.tablayout)
    TabLayout tablayout;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.tv_title)
    TextView tv_title;
    private MineSellPresenter presenter;

    @Override
    public int getLayout() {
        return R.layout.activity_mine_buy;
    }

    @Override
    protected MineSellPresenter getPresenter() {
        if (presenter == null) {
            presenter = new MineSellPresenter(this, this);
        }
        return presenter;
    }

    @Override
    protected void initEventAndData() {
        QMUIStatusBarHelper.translucent(this);
        QMUIStatusBarHelper.setStatusBarDarkMode(this);
        initViewpager();
        String title = getIntent().getStringExtra("type");
        tv_title.setText(title);


    }

    private void initViewpager() {
        ArrayList<String> mlist = new ArrayList<>();
        for(int i = 0;i<=5;i++){
            mlist.add("dd");
        }

        MyPagerAdapter myPagerAdapter = new MyPagerAdapter(getSupportFragmentManager(), mlist);
        viewpager.setOffscreenPageLimit(3);
        viewpager.setAdapter(myPagerAdapter);
        tablayout.setupWithViewPager(viewpager);
    }

    @Override
    public void onFailer(Throwable throwable) {

    }

    @Override
    public void onOrderList(AllInfoBean infoBean) {

    }

    @Override
    public void onChangeOrder(AllInfoBean infoBean) {

    }

    @Override
    public void onMyGoodList(AllInfoBean infoBean) {
        //空
    }

    @Override
    public void onPageMyGoodList(AllInfoBean infoBean) {
        //空
    }

    @Override
    public void onPageOrderList(AllInfoBean infoBean) {
        //空
    }


    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }


    class MyPagerAdapter extends FragmentPagerAdapter {
        private List<String> mDataList;

        public MyPagerAdapter(FragmentManager fm, List<String> dataList) {
            super(fm);
            this.mDataList = dataList;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position){
                case 0:
                    return "全部";
                case 1:
                    return "待被买";
                case 2:
                    return "已锁单";
                case 3:
                    return "待确认收款";
                case 4:
                    return "已完成";
                default:
                    return "待入场";
            }
        }

        @Override
        public Fragment getItem(int position) {
            if(position == 0){
                return MineSellTabFragment.newInstance(100);//mUser_score
            }else if(position == 1){
                return MineSellMallTabFragment.newInstance(10);//MineSellTabFragment.newInstance(1)
            }else if(position == 2){
                return MineSellTabFragment.newInstance(2);//mUser_score
            }else if(position == 3){
                return MineSellTabFragment.newInstance(3);//mUser_score
            }else if(position == 4){
                return MineSellTabFragment.newInstance(5);//mUser_score
            }else {
                return MineSellTabFragment.newInstance(0);//mUser_score
            }
        }

        @Override
        public int getCount() {
            return mDataList == null ? 0 : mDataList.size();
        }
//
//        @Override
//        public int getItemPosition(Object object) {
//            return PagerAdapter.POSITION_NONE;
//        }

    }

}
